package com.huage_07.lesson_04;

import java.io.*;

public class CopyFolderDemo {
    public static void main(String[] args) throws IOException {
        File srcFolder = new File("D:\\document\\java\\CopyTest\\Test");

        String folderName = srcFolder.getName();

        File destFolder = new File("class1\\src\\com\\huage_07\\lesson_04",folderName);

        if(!destFolder.exists()){
            destFolder.mkdir();
        }
        File[] files = srcFolder.listFiles();
        for (File srcFile : files){
            String srcName = srcFile.getName();
            File destFile = new File(destFolder,srcName);

            copyFile(srcFile,destFile);
        }


    }
    public static void copyFile(File srcfile,File destfile)throws IOException{
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcfile));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destfile));

        byte[] bytes = new byte[1024];
        int len;
        while ((len=bis.read(bytes))!=-1){
            bos.write(bytes,0,len);
        }

        bis.close();
        bos.close();

    }
}
